<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>添加电影</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
	<link rel="stylesheet" type="text/css" href="../layui/css/layui.css" media="all">
	<style>
		body{
			text-align: center;
			/* 初始化 取消内外边距 */
			margin: 0;
			padding: 0;
			/* 100%窗口高度 */
			height: 100vh;
			/* 渐变背景 */
			background: linear-gradient(125deg,#2c3e50,#27ae60,#2980b9,#e74c3c,#8e44ad);
			/* 指定背景图像的大小 */
			background-size: 500%;
			/* 执行动画：动画名 时长 线性的 无限次播放 */
			animation: bgAnimation 15s linear infinite;
		}

		/* 定义动画 */
		@keyframes bgAnimation {
			0%{
				background-position: 0% 50%;
			}
			50%{
				background-position: 100% 50%;
			}
			100%{
				background-position: 0% 50%;
			}
		}
	</style>
>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	<legend>添加管理员信息</legend>
</fieldset>
<form class="layui-form" action="" id="form_admin">
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">管理员名</label>
			<div class="layui-input-inline">
				<input type="hidden" name="op" value="add" autocomplete="off" class="layui-input">
				<input type="text" name="adminName" autocomplete="off" class="layui-input" lay-verify="adminName">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">密码</label>
			<div class="layui-input-inline">
				<input type="text" name="adminPassword" lay-verify="adminPassword" autocomplete="off" class="layui-input">
			</div>
		</div>
	</div>

	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">角色</label>
			<div class="layui-input-inline">
				<select name="adminType">
					<option value="超级管理员" >超级管理员</option>
					<option value="普通管理员" selected="" >普通管理员</option>
				</select>
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label"></label>
			<div class="layui-input-inline">
				<button type="submit" class="layui-btn" lay-submit="" lay-filter="add">添加</button>
			</div>
		</div>
	</div>
</form>
<div style="margin-top: 20px;height: 1000px;border-top:1px solid gainsboro;">
	<table class="layui-hide" id="test" lay-filter="test" ></table>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="update">修改状态</a>
	</script>
</div>
<script src="../layui/layui.js" charset="utf-8"></script>
<script>
	layui.use(['table','form'],function (){
		var table=layui.table,
				$=layui.jquery,
				form=layui.form;
		var tableIns=table.render({
			elem: '#test'
			,url: '../admin?op=findPage'
			,title: '管理员数据表'
			,cols:[[
				{type: 'checkbox',fixed:'left'}
				,{field: 'adminId', title:'管理员编号', width: 180, fixed: 'left', unresize: true, sort: true}
				,{field: 'adminName', title:'管理员名称', width: 180, edit: 'text' }
				,{field: 'adminPassword', title:'管理员密码', width: 180, edit: 'text'}
				,{field: 'adminType', title:'管理员类型',edit: 'text', sort: true}
				,{
					field: 'adminStatus', title: '状态', edit: 'text',templet: function (res){
						if(res.adminStatus==1){
							return "<span style='color: green'>正常</span>";
						}else {
							return "<span style='color: gainsboro'>冻结</span>";
						}
					}
				}
				,{field: 'right', title: '操作', toolbar: '#barDemo',width: 150}
			]]
			,page:{
				limits: [2,3,4,10],
				limit: 2,
				groups: 3,
				first: '首页',
				last: '尾页'
			}
		});
		table.on('tool(test)',function (obj){
			var data=obj.data;
			if(obj.event== 'update'){
				let ano=data.adminId;
				$.get("../admin?op=update",{adminId: data.adminId},function (rs){
					if(rs.code==200){
						layer.msg(rs.msg);
						tableIns.reload();
					}else{
						layer.msg(rs.msg);
					}
				},'json');
			}
		});
		form.verify({
			aname:function (value){
				if(value.length<2){
					return '账号至少两个字符';
				}
			}
		});
		form.on('submit(add)',function (data){
			var obj =JSON.stringify(data.field);
			console.log(obj);
			alert(obj);
			$.post("../admin?op=add",data.field,function (rs){
				if(rs==1){
					alert("添加成功！！");
					$("#form_admin")[0].reset();
					layui.form.render();//重新渲染表单
					tableIns.reload();//重新加载表格数据
				}else{
					alert("添加失败！！");
					layer.msg(rs.msg);
				}
			},'json');
			return false;
		});
	});
</script>
</body>
</html>